<?php include "include/function_library.php"; ?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php include "html/header.html"; ?>

</head>
<body class="tcuk home">

	<div id="wp">
	
		<?php  include "html/menu.html"; ?>
		
		<!-- CONTENT STARTS-->
		<div id="ct"> 	
			
			<?php 
			if(post("transportation_submit")) {
				
				$transportation_source 		= post("transportation_source");
				$transportation_destination = post("transportation_destination");
				$transportation_date 		= post("transportation_date");
				$transportation_capacity 	= post("transportation_capacity");
				$transportation_type 		= post("transportation_type");
				$transportation_price 		= post("transportation_price");
				$transportation_description	= post("transportation_description");
				$transportation_id			= post("$id");
				
				$query = "update transportation set source='$transportation_source', 
													destination='$transportation_destination', 
													date='$transportation_date', 
													price='$transportation_price', 
													type='$transportation_type', 
													description='$transportation_description',
													capacity='$transportation_capacity' 
												where id = $transportation_id";
				
				$result = sql_query($query);
				
				if($result) {
					redirect("transportation_detail.php?edited=1&id=$transportation_id");
				} else {
					echo "<div class='alert error'>Error! Could Not Update! There is(are) error(s) in the form!</div>";
				}
			} 
			
			$query = "SELECT * FROM transportation WHERE id=".get("id");
			$result = sql_query($query);
			$tuple = mysql_fetch_assoc($result);
			
			?>
			<form action="<?php echo curPageURL(); ?>?id=<?php echo get("id"); ?>" method="post">
			<ul id="signup_form" style="width: 50%; margin-left: auto; margin-right: auto; margin-top: 30px; list-style: none;">
				<li style="border: none;">
					<label>Source</label>
					<input type="text" id="transportation_source" name="transportation_source" value="<?php echo $tuple["source"]; ?>" placeholder="Transportation source.." style="width: 250px;"/>
				</li>
				<li>
					<label>Destination </label>
					<input type="text" id="transportation_destination" name="transportation_destination" value="<?php echo $tuple["description"]; ?>" placeholder="Transportation description.." style="width: 250px;"/>
				</li>
				<li>
					<label>Date </label>
					<input type="number"  id="transportation_date" name="transportation_date" value="<?php echo $tuple["date"]; ?>" placeholder="Transportation date.." style="width: 250px;"/>
				</li>
				<li>
					<label>Capacity </label>
					<input type="number"  id="transportation_capacity" name="transportation_capacity" value="<?php echo $tuple["capacity"]; ?>" placeholder="Transportation capacity.." style="width: 250px;"/>
				</li>
				<li>
					<label>Type </label>
					<select id="transportation_type" name="transportation_type">
						<option value="Bus" selected="<?php $tuple["type"] == 'Bus' ?>">Bus</option>
						<option value="Plane" selected="<?php $tuple["type"] == 'Plane' ?>">Plane</option>
						<option value="Ship" selected="<?php $tuple["type"] == 'Ship' ?>">Ship</option>
						<option value="Train" selected="<?php $tuple["type"] == 'Train' ?>">Train</option>
					</select>
				</li>
				<li>
					<label>Price</label>
					<input type="number" id="transportation_price" name="transportation_price" value="<?php echo $tuple["price"]; ?>" placeholder="Transportation price.." style="width: 120px;"/>
				</li>
				<li>
					<label>Description </label>
					<textarea rows="10" id="transportation_description" name="transportation_description" placeholder="Transportation description.." style="width: 250px;"><?php echo $tuple["description"]; ?></textarea>
				</li>
				<li>
					<input type="hidden" name="id" value="<?php echo get("id"); ?>"/>
					<input type="submit" id="transportation_submit" name="transportation_submit" value="Save" style="width: 90px; height:30px; margin-left: 80px;"/>
				</li>
			</ul>
			</form>
		
		</div> 	
		<!-- CONTENT ENDS-->		
		
		<?php include "html/footer.html"; ?>
		
	</div>
	
</body>
</html>